<?php
class type_model extends jqxGrid_CI_Model {

    function __construct()
    {
        parent::__construct();
        
    }
    
    function get($ID){
        $where=array('ID'=>$ID);
        $query=$this->db->get_where("tbl_type", $where); 
        return $query->result();
    }
    function gets(){
        $where=array('Delete'=>NULL);
        $query=$this->db
                ->where($where)
                ->get("tbl_type"); 
        return $query->result();
    }
    function getfoots(){
        $where=array('Delete'=>NULL,"Status"=>"true","Fun"=>"Footer");
        $query=$this->db
                ->where($where)
                ->get("tbl_type"); 
        return $query->result_array();
    }
    function getPartners(){
        $where=array('Delete'=>NULL,"Status"=>"true","Fun"=>"Partner");
        $query=$this->db
                ->where($where)
                ->get("tbl_type"); 
        return $query->result_array();
    }
    function getLeftMenus(){
        $where=array('Delete'=>NULL,"Status"=>"true","Fun"=>"LeftMenu");
        $query=$this->db
                ->where($where)
                ->order_by("Type","ASC")
                ->get("tbl_type"); 
        return $query->result_array();
    }
    function getByType($type=""){
        $where=array('Delete'=>NULL,"Type"=>$type);
        $query=$this->db
                ->where($where)
                ->get("tbl_type"); 
        return $query->result();
    }
    function insert($params){
        $this->db->set('Insert', 'NOW()', FALSE);
        $this->db->insert("tbl_type", $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function delete($ID){
        $this->db->set('Delete', 'NOW()', FALSE);
        $where=array('ID'=>$ID);
        $this->db->where($where);
        $this->db->update("tbl_type"); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function retore($ID){
        $this->db->set('Delete', 'NULL', FALSE);
        $where=array('ID'=>$ID);
        $this->db->where($where);
        $this->db->update("tbl_type"); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function update($ID,$params){
        $this->db->set('Update', 'NOW()', FALSE);
        $this->db->where('ID', $ID);
        $this->db->update("tbl_type", $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function binding(){
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `tbl_type`.*
            FROM `tbl_type`
            ";
        $strWhere="
            WHERE  `Fun` IS NULL
            ";
        if($_SESSION["ADP"][CCTRL]["display"]==0){
            $strWhere.=" AND `Delete` IS NULL";
        }elseif($_SESSION["ADP"][CCTRL]["display"]==-1){
            $strWhere.=" AND `Delete` IS NOT NULL";
        }
        $strOrderBy="Order By `Insert` DESC ";
        $strGroupBy="";
        $config=array(
            "strQuery"=>$strQuery,
            "strWhere"=>$strWhere,
            "strOrderBy"=>$strOrderBy,
            "strGroupBy"=>$strGroupBy,
            "usingLimit"=>false,
            "fields"=>array(),
            "datefields"=>array()
        );
        $this->init($config);
        return $this->jqxBinding();
    }
    function binding_foot(){
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `tbl_type`.*
            FROM `tbl_type`
            ";
        $strWhere="
            WHERE  `Fun` ='Footer'
            ";
        if($_SESSION["ADP"][CCTRL]["display"]==0){
            $strWhere.=" AND `Delete` IS NULL";
        }elseif($_SESSION["ADP"][CCTRL]["display"]==-1){
            $strWhere.=" AND `Delete` IS NOT NULL";
        }
        $strOrderBy="Order By `Insert` DESC ";
        $strGroupBy="";
        $config=array(
            "strQuery"=>$strQuery,
            "strWhere"=>$strWhere,
            "strOrderBy"=>$strOrderBy,
            "strGroupBy"=>$strGroupBy,
            "usingLimit"=>false,
            "fields"=>array(),
            "datefields"=>array()
        );
        $this->init($config);
        return $this->jqxBinding();
    }
    function binding_left_menu(){
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `tbl_type`.*
            FROM `tbl_type`
            ";
        $strWhere="
            WHERE  `Fun` ='LeftMenu'
            ";
        if($_SESSION["ADP"][CCTRL]["display"]==0){
            $strWhere.=" AND `Delete` IS NULL";
        }elseif($_SESSION["ADP"][CCTRL]["display"]==-1){
            $strWhere.=" AND `Delete` IS NOT NULL";
        }
        $strOrderBy="Order By `Insert` DESC ";
        $strGroupBy="";
        $config=array(
            "strQuery"=>$strQuery,
            "strWhere"=>$strWhere,
            "strOrderBy"=>$strOrderBy,
            "strGroupBy"=>$strGroupBy,
            "usingLimit"=>false,
            "fields"=>array(),
            "datefields"=>array()
        );
        $this->init($config);
        return $this->jqxBinding();
    }
    function binding_partner(){
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `tbl_type`.*
            FROM `tbl_type`
            ";
        $strWhere="
            WHERE  `Fun` ='Partner'
            ";
        if($_SESSION["ADP"][CCTRL]["display"]==0){
            $strWhere.=" AND `Delete` IS NULL";
        }elseif($_SESSION["ADP"][CCTRL]["display"]==-1){
            $strWhere.=" AND `Delete` IS NOT NULL";
        }
        $strOrderBy="Order By `Insert` DESC ";
        $strGroupBy="";
        $config=array(
            "strQuery"=>$strQuery,
            "strWhere"=>$strWhere,
            "strOrderBy"=>$strOrderBy,
            "strGroupBy"=>$strGroupBy,
            "usingLimit"=>false,
            "fields"=>array(),
            "datefields"=>array()
        );
        $this->init($config);
        return $this->jqxBinding();
    }
}
?>
